import {createRouter, createWebHistory, createWebHashHistory} from 'vue-router'
import { defineAsyncComponent } from 'vue'



 
 
 
 
//2、构建路由规则
const myRoutes=[
   
    {
        path:"/",
        name:"One",
        component: defineAsyncComponent(() => import(`../components/Login.vue`)),
            },
	
	// {
	// 	path:"/login",
	// 	name:"Login",
	// 	component: defineAsyncComponent(() => import(`../components/Login.vue`)),
	// 		},
			
	{
		path:"/register",
		name:"Register",
		component: defineAsyncComponent(() => import(`../components/Register.vue`)),
			},
	{
		path:"/user",
		name:"User",
		component: defineAsyncComponent(() => import(`../components/user.vue`)),
			},
	{
	    path:"/home",
	    name:"Home",
	    component: defineAsyncComponent(() => import(`../pages/Home.vue`)),
	        },
			
	{
	    path:"/home2",
	    name:"Home2",
	    component: defineAsyncComponent(() => import(`../pages/Home2.vue`)),
	        },
			
	{
	    path:"/feedback",
	    name:"feedback",
	    component: defineAsyncComponent(() => import(`../components/feedback.vue`)),
	        },
	{
	    path:"/ask",
	    name:"Ask",
	    component: defineAsyncComponent(() => import(`../components/ask.vue`)),
	        },
			
	{
	    path:"/remtrans",
	    name:"remTrans",
	    component: defineAsyncComponent(() => import(`../components/remTrans.vue`)),
	        },


    {
	    path:"/dwmoney",
	    name:"dwmoney",
	    component: defineAsyncComponent(() => import(`../components/DWmoney.vue`)),
	        },


    {
	    path:"/depmoney",
	    name:"depmoney",
	    component: defineAsyncComponent(() => import(`../components/DepMoney.vue`)),
	        },
			
	{
	    path:"/checktrans",
	    name:"checktrans",
	    component: defineAsyncComponent(() => import(`../components/checkTrans.vue`)),
	        },
			
			
        ]

 
 
//3、创建路由对象
const router=createRouter({
    history:createWebHistory(),
    routes:myRoutes
})
 
 
//4、加入导航守卫
// 前置
router.beforeEach(async (to, from,next) => {
	if (to.fullPath=='/cart' || to.fullPath=='/user') {
	    let token = localStorage.getItem('token')
	    if(token) {
	      next()
	    } else {
	      next('/login')
	    }
	  } else {
	    next()
	  }
   
})
 
//5、导出路由对象
export default router
